package com.funny.learning.english.adapter;

import java.io.File;
import java.util.ArrayList;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.TextView;

import com.funny.learning.english.R;
import com.funny.learning.english.model.GameEntity;

public class WellcomeAdapter extends PagerAdapter {

	private LayoutInflater inflater;
	private Context mContext;
	
	private ClickListener clickListener;
	
	private File file;

	public WellcomeAdapter(Context context) {
		this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mContext = context;
	}

	@Override
	public int getCount() {
		return 4;
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		return view.equals(object);
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		container.removeView((View) object);
	}

	/*
	 * @Override public Object instantiateItem(View container, int position) {
	 * View v = inflater.inflate(R.layout.slide_home_item, null); assert v !=
	 * null; container.ad return super.instantiateItem(container, position); }
	 */

	@Override
	public Object instantiateItem(ViewGroup container, final int position) {
		ImageView imageView = new ImageView(mContext);
		imageView.setScaleType(ScaleType.CENTER_CROP);
		imageView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
		if(position == 0){
			imageView.setImageResource(R.drawable.iv_pager1);
		}else if(position == 1){
			imageView.setImageResource(R.drawable.iv_pager2);
		}else if(position == 2){
			imageView.setImageResource(R.drawable.iv_pager1);
		}else if(position == 3){
			imageView.setImageResource(R.drawable.iv_pager2);
		}
		container.addView(imageView, 0);
		return imageView;
	}
	
	
	
	public ClickListener getClickListener() {
		return clickListener;
	}

	public void setClickListener(ClickListener clickListener) {
		this.clickListener = clickListener;
	}



	public interface ClickListener{
		void onPre();
		void onNext();
		void getSound(GameEntity gameEntity);
	}
	
	public String getPathImg(GameEntity gameEntity) {
		if (gameEntity.getUrl() == null)
			return null;
		return file.getPath() + File.separator + gameEntity.getUrl();
	}

}
